#include "app.h"
#include "font.h"
#include "scrollskin.h"
#include "knobskin.h"
#include "buttonskin.h"

App::App() 
: m_patternEditor(&m_song), m_pConfig(NULL) {
     m_pConfig = al_load_config_file("7bw.conf");
     if (m_pConfig)
	  m_keyBindings.init(m_pConfig);
     setupSkin();
     m_player.setSong(&m_song);
     m_player.start();
}

App::~App() {
     if (m_pConfig)
	  al_destroy_config(m_pConfig);
     m_player.quit();
}

// initialize default skin
void App::setupSkin() {
     m_skin.setFont(new Font("images/7x14.png", 7, 14));
     m_skin.setScrollSkin(new ScrollSkin("images/scroll.png", 15));
     m_skin.setKnobSkin(new KnobSkin("images/knobsheet.png", 30, 20));
     m_skin.setColor(Skin::FgColor, al_map_rgb(255,255,255));
     m_skin.setColor(Skin::BgColor, al_map_rgb(0,0,0));
     m_skin.setColor(Skin::CursorColor, al_map_rgb(0,0,255));
     m_skin.setColor(Skin::HighlightColor, al_map_rgb(100,255,190));
     m_skin.setColor(Skin::HighlightColor2, al_map_rgb(255,230,50));
     m_skin.setColor(Skin::PlayingColor, al_map_rgba(75,200,0,65));
     m_skin.setColor(Skin::StoppedColor, al_map_rgba(255,20,0,100));
     m_skin.setColor(Skin::SelectedItemColor, al_map_rgba(130,255,190,75));
     m_skin.setColor(Skin::ButtonDownColor, al_map_rgba(130,255,190,50));
     m_skin.setButtonSkin(Skin::AddButton, 
			  new ButtonSkin("images/add.png", 15, 15,
					 m_skin.color(Skin::ButtonDownColor)));
     m_skin.setButtonSkin(Skin::DelButton, 
			  new ButtonSkin("images/del.png", 15, 15,
					 m_skin.color(Skin::ButtonDownColor)));

}

Skin* App::skin() {
     return &m_skin;
}

Song* App::song() {
     return &m_song;
}

PatternEditor* App::patternEditor() {
     return &m_patternEditor;
}

KeyBindings* App::keyBindings() {
     return &m_keyBindings;
}

Player* App::player() {
     return &m_player;
}
